<?php
get_header();
?>
<div class="clear" />

<div id="content">
	<!-- Start slider -->
	<div id="slider">
		<p>  slideshow </p>
	<!-- End slider -->
	</div>

	<!-- sidebar -->
	<div id ="aside">
	<?php get_sidebar(); ?>
	<!-- End of aside -->
	</div>
	<!-- Entries -->
		<?php	
	//start checking for posts
	if ( have_posts() ) : while ( have_posts() ) : the_post();
	?>
	<div class="entries">
		<?php
		//Get image from post	
		$id =$post->ID;
		$the_content =$wpdb->get_var("SELECT post_content FROM $wpdb->posts WHERE ID = $id");
		$pattern = '!<img.*?src="(.*?)"!';
		preg_match_all($pattern, $the_content, $matches);
		$image_src = $matches['1'][0];
		// Entry-link
		?><a href="<?php the_permalink() ?>" rel="bookmark" class="title">
		<?php
		// Display image if image exists
		if($image_src != ''){		
			?><img src="<?php echo $image_src ?>" style="width: 480px; height: 300px;"/>
			<?php } 
			// Get excerpt if not under 20 chars
			$myExcerpt = get_the_excerpt();
			if(strlen($myExcerpt) < 20) {
				$myExcerpt = '';
			}
			// Add title and excerpt
			?>
			<h2><?php echo get_the_title();?></a></h2>
  			<?php echo $myExcerpt;
			?> <span class="comments"><?php comments_popup_link('', '1 kommentar', '(%) kommentarer'); ?></span>
	<!-- End of entry -->
	</div>
	<?php
	//stop checking for posts
	endwhile; else:
	?>
	<p>
		<?php _e('Inga inlägg hittades.');?>
	</p>
	<?php endif;
	// Show next/previous page
	next_posts_link('<< Äldre inlägg'); 
	previous_posts_link('Nyare inlägg >>'); ?>
<!-- End of container -->	
</div>
<?php get_footer(); ?>